#include "../include/head.h"
#include <stdio.h>

//菜单
void menu(void)
{
    char m[3][100]={"1.学生系统","2.教师系统","3.退出"};
    printf("\n----------------------------\n学生管理系统\n------------------------\n");
    for (int i=0;i<3;i++)
    printf("%s\n",m[i]);
    printf("----------------------------\n");
}

int main(int argc, char const *argv[])
{
    printf("\n------------------------------------\n");
    printf("Welcome to Student Management System !\n");
    printf("------------------------------------\n");
   load_users();
    Pnode_list read_H = creat_list();
    read_file(read_H);
    
    while (1) {
        welcome_menu();
        int choice;
        scanf("%d", &choice);
        getchar();
        
        switch (choice) {
            case 1:
                system("clear");
                if (login(&current_user)) {
                    if (current_user.is_teacher) {
                        tea_manage();
                    } else {
                        stu_manage();
                    }
                }
                system("clear");
                break;
            case 2:
                system("clear");
                printf("1. 注册教师账号\n2. 注册学生账号\n选择: ");
                int reg_choice;
                scanf("%d", &reg_choice);
                getchar();
                register_user(reg_choice == 1);
                
                break;
            case 3:
                // write_file(read_H);
                // clear_list(read_H);
                // free(read_H);
                printf("系统已退出\n");
                return 0;
            default:
        
                printf("无效选择!\n");
        }
    }
}

// 界面
void welcome_menu() {
    printf("\n===== 学生管理系统 =====\n");
    printf("1. 登录\n");
    printf("2. 注册\n");
    printf("3. 退出\n");
    printf("请选择: ");
}